/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mycompany.psc.controllers;

import com.mycompany.psc.producers.Auth;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.inject.Named;
import org.apache.commons.codec.binary.Base64;


/**
 *
 * @author A7med
 */
@Named @Auth
public class Authintactor {
     public synchronized String encrypt(String plaintext) {
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("SHA-256"); //step 2
        } catch (NoSuchAlgorithmException e) {

        }
        try {
            md.update(plaintext.getBytes("UTF-8")); //step 3
        } catch (UnsupportedEncodingException e) {

        }

        byte raw[] = md.digest(); //step 4
        String hash = Base64.encodeBase64String(raw); //step 5
        return hash; //step 6
    }
}
